<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *员工管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'活动列表'),
	array('op'=>'edit','title'=>'添加活动'),	
);
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','paixu','uniacid','title','thumb','starttime','endtime','status','isrecommend','createtime','groupid');
	$list=pdo_getslice('jy_vote_reply',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['starttime']=date('Y-m-d H:i',$item['starttime']);
			$item['endtime']=date('Y-m-d H:i',$item['endtime']);
			$group=pdo_get('jy_vote_groups',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['groupid']));
			$item['gtitle']=$group['title'];
			$item['url']=custom_url('jy_vote/r_detail//isdownsao=1&id='.$item['id'],true);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>true,'list'=>array(
			array('name'=>'title','title'=>'活动名称','type'=>'string'),
			array('name'=>'gtitle','title'=>'所属分类','type'=>'string'),
			array('name'=>'thumb','title'=>'活动封面','type'=>'image'),
			array('name'=>'starttime','title'=>'开始时间','type'=>'string'),
			array('name'=>'endtime','title'=>'结束时间','type'=>'string'),
			array('name'=>'isrecommend','title'=>'是否推荐','type'=>'switch','set'=>'set'),
			array('name'=>'status','title'=>'状态','type'=>'switch','set'=>'set'),
			array('name'=>'url','title'=>'复制链接','type'=>'copy'),
			array('name'=>'url','title'=>'二维码','type'=>'ewm'),
		),'action' => 
		    array (
				array('type'=>'post','op'=>'max_get','title'=>'发冠军奖'),
			    array('type'=>'href','op'=>'jplist','title'=>'礼品管理'),
				array('type'=>'href','op'=>'votelog','title'=>'投票记录'),
		),
		),
		'search'=>array(
			array('name'=>'title','width'=>15,'title'=>'活动名称','type'=>'string'),
			array('name'=>'status','width'=>15,'title'=>'状态','type'=>'select','options'=>'status'),
		)
	);
	$return['status']=array(
		array('id'=>'0','title'=>'关闭'),
		array('id'=>'1','title'=>'开启'),	
	);
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='edit'){
	$return=array();
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_vote_reply',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$item['starttime']=date('Y-m-d H:i',$item['starttime']);
		$item['endtime']=date('Y-m-d H:i',$item['endtime']);
	//	$item['jiangpin']=$item['jiangpin']?json_decode($item['jiangpin'],true):array();
		$item['systype']=pdo_getcolumn('jy_vote_groups',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['groupid']),'type');
		$item['jiangpin']=pdo_getall('jy_vote_liping',array('rid'=>$id,'uniacid'=>$_SESSION['uniacid']),'','','id asc');
		$item['onlinetime']=json_decode($item['onlinetime'],true);
	}else{
		$footernav =array(
			array('title'=>'首页','icon'=>'icon-shouye','action'=>'jy_vote/index/'),
			array('title'=>'作品','icon'=>'icon-map','action'=>'jy_vote/o_list/'),
			array('title'=>'我的','icon'=>'icon-wo1','action'=>'jy_vote/home/'),
		);
		$item=array('footernav'=>$footernav);
	}
	$hdps =array(
		array('title'=>'幻灯片','picurl'=>'../addons/jy_vote/resource/img/hdp01.jpg'),
	);
	$item['hdps']=$item['hdps']?json_decode($item['hdps'],true):$hdps;
	$item['bankuai']=$item['bankuai']?json_decode($item['bankuai'],true):array();
	$item['footernav']=$item['footernav']?json_decode($item['footernav'],true):array();
	$item['fileds']=json_decode($item['fileds']);
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回活动列表'),
		),
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('name'=>'title','title'=>'活动名称','type'=>'string'),
					array('name'=>'groupid','title'=>'所属分类','type'=>'select','options'=>'groupid'),
					array('name'=>'paixu','title'=>'排序','type'=>'string'),
					array('name'=>'thumb','title'=>'活动封面','type'=>'image'),
					array('name'=>'starttime','title'=>'开始时间','type'=>'time','help'=>''),
					array('name'=>'endtime','title'=>'结束时间','type'=>'time','help'=>''),
					array('name'=>'infomsg','title'=>'活动介绍','type'=>'text'),
					array('name'=>'isrecommend','title'=>'是否推荐','type'=>'switch'),
					array('name'=>'type','title'=>'投票模式','type'=>'radio','options'=>'type'),
					array('name'=>'status','title'=>'状态','type'=>'switch'),
					array('name'=>'showtype','title'=>'展示形式','type'=>'radio','options'=>'showtype','help'=>'视频模式：支持抖音视频，微信短视频！'),
					array('type'=>'image','title'=>'默认封面','name'=>'noimg','help'=>'默认封面,建议尺寸：高500px*宽320px'),
					array('name'=>'nofabu','title'=>'后台发布','type'=>'switch','help'=>'开启后台发布后，客户不能发布作品，统一又后台发布'),
					array('name'=>'price','title'=>'发布作品费用','type'=>'unitstring','unit'=>'元','help'=>'不填则无需支付费用，就能参与发布作品！'),
				)
			),
			array(
				'title'=>'礼品设置',
				'list'=>array(
					array('name'=>'nojiangpin','title'=>'关闭礼品','type'=>'switch'),
					/*array(
							'type'=>'array',
							'name'=>'jiangpin',
							'add_tip'=>'添加一个礼品',
								'list'=>array(
									array('type'=>'image','name'=>'picurl','title'=>'礼品图片'),
									array('type'=>'string','name'=>'title','title'=>'礼品名称'),
									array('type'=>'string','name'=>'price','title'=>'礼品价格'),
									array('type'=>'string','name'=>'jifen','title'=>'礼品积分(票数/赞数)'),
									//array('type'=>'string','name'=>'jifen','title'=>'礼品积分(赞数)','show'=>array('type',1)),
								),
								'details'=>array(
									array('type'=>'image','name'=>'picurl','title'=>'礼品图片'),
									array('type'=>'string','name'=>'title','title'=>'礼品名称'),
									array('type'=>'string','name'=>'price','title'=>'礼品价格'),
									array('type'=>'string','name'=>'jifen','title'=>'礼品积分(票数/赞数)','help'=>'(由绑定的分类决定是投票还是集赞)1积分等于1票或1赞'),
								)
						)*/
				)
			),
				array(
				'title'=>'规则设置',
				'list'=>array(
					array('type'=>'switch','title'=>'限制时间段？','name'=>'is_linetime','help'=>'不设置则不限制！'),
					array('name'=>'onlinetime','title'=>'投票时间段','type'=>'time_hour','show'=>array('is_linetime'=>1)),
					array('title'=>'数量限制','name1'=>'timnei','unit1'=>'分','title1'=>'多少分钟内','type'=>'string_two','name2'=>'timnei_num','unit2'=>'票','title2'=>'投票上限'),
					array('name'=>'isfollow','title'=>'是否需要关注','type'=>'radio','options'=>'isfollow'),
					//array('name'=>'is_shenhe','title'=>'投票是否审核','type'=>'radio','options'=>'is_shenhe'),
					array('type'=>'switch','title'=>'开启多选投票','name'=>'is_votemore','help'=>'开启后前台可以多选，投票！'),
					//array('name'=>'max_votemore','title'=>'每人每日最多投票N人','type'=>'unitstring','unit'=>'人',),
					array('name'=>'maxfabu','title'=>'每人最多发布作品','type'=>'unitstring','unit'=>'个',),
					array('name'=>'minpeople','title'=>'投票需达到的最小人数','type'=>'unitstring','unit'=>'人',),
					array('name'=>'everyoneuser','title'=>'每人每日给同一用户最多投票','type'=>'unitstring','unit'=>'票','help'=>''),
					array('name'=>'dairyvote','title'=>'每人每日最多投票','type'=>'unitstring','unit'=>'票','help'=>''),
					array('name'=>'everyonevote','title'=>'每人最多投票','type'=>'unitstring','unit'=>'票'),
					array('name'=>'songli_max','title'=>'每人最多送礼价值','type'=>'unitstring','unit'=>'元',),
					array('name'=>'shouli_max','title'=>'参赛作品最多收礼价值','type'=>'unitstring','unit'=>'元',),
					array('name'=>'is_niming','title'=>'是否匿名送礼','type'=>'switch'),
					array('name'=>'is_yanzheng','title'=>'投票验证码','type'=>'switch'),
				)
			),
			array(
				'title'=>'投票设置',
				'list'=>array(
					array('name'=>'rules','title'=>'活动规则','type'=>'text'),
					array('name'=>'jiangpin_desc','title'=>'礼品介绍','type'=>'richtext'),
				)
			),
			array(
				'title'=>'界面设置',
				'list'=>array(
					array('name'=>'shunxu','title'=>'首页显示顺序','type'=>'radio','options'=>'shunxu'),
					array('name'=>'gonggao','title'=>'活动公告','type'=>'text'),
				)
			),
			array(
				'title'=>'奖励设置',
				'list'=>array(
					array('type'=>'radio','title'=>'票数冠军奖励类型','name'=>'max_type','options'=>'gift_type','help'=>'可以选择：优惠券，虚拟币等'),
					array('name'=>'max_couponid','title'=>'选择优惠券','type'=>'choose_title','action'=>'jy_weishop/coupon.get_coupon/','show'=>array('max_type'=>0)),
					array('type'=>'unitstring','title'=>'票数冠军奖励虚拟币数量','unit'=>'个','name'=>'max_credit_fee','show'=>array('max_type >'=>0)),
					array('type'=>'radio','title'=>'参与投票奖励类型','name'=>'vote_type','options'=>'gift_type','help'=>'可以选择：优惠券，虚拟币等'),
					array('name'=>'vote_couponid','title'=>'选择优惠券','type'=>'choose_title','action'=>'jy_weishop/coupon.get_coupon/','show'=>array('vote_type'=>0)),
					array('type'=>'unitstring','title'=>'参与投票奖励虚拟币数量','unit'=>'个','name'=>'votezs','show'=>array('vote_type >'=>0)),
					array('name'=>'fabuzs','title'=>'参赛赠送(给参赛者)','type'=>'string','help'=>'(给参赛者)填写赠送的积分数：例如：10'),
					array('name'=>'songlizs','title'=>'送礼赠送(给送礼者)','type'=>'string','help'=>'(给送礼者)填写赠送的积分数：例如：10'),
					array('name'=>'songlijl','title'=>'送礼奖励(给参赛者)','type'=>'string','help'=>'(给参赛者)填写赠送的积分数：例如：10'),
					array('type'=>'radio','title'=>'参与投票送券码','name'=>'vote_codetype','options'=>'code_type','help'=>'配合线下投票活动使用,券码随机生成！'),
				)
			),
			array(
				'title'=>'投票红包设置',
				'list'=>array(
					array('name'=>'hb_no','title'=>'是否关闭送红包功能','type'=>'switch','help'=>'关闭后，不显示赠送红包按钮'),
					array('name'=>'hb_draw','title'=>'是否开启投票后抽奖','type'=>'switch'),
					array('name'=>'tanchu_rate','title'=>'投票弹出红包窗口概率','type'=>'unitstring','unit'=>'%'),
					array('name'=>'hb_rate','title'=>'用户抽奖获得红包的概率','type'=>'unitstring','unit'=>'%'),
					array('name'=>'hb_sum','title'=>'红包总数','type'=>'unitstring','unit'=>'个'),
					array('name'=>'dairyhb','title'=>'每日红包数量','type'=>'unitstring','unit'=>'个'),
					array('name'=>'dairyuserhb','title'=>'每人每日最多获得红包数量','type'=>'unitstring','unit'=>'个'),
					array('name'=>'minhb','title'=>'最小面额','type'=>'unitstring','unit'=>'元','help'=>'最小面额需大于1元，可填写1.01'),
					array('name'=>'maxhb','title'=>'最大面额','type'=>'unitstring','unit'=>'元','help'=>'最大面额需小于等于200元'),
					array('name'=>'hb_title','title'=>'活动名称','type'=>'string'),
					array('name'=>'shanghu_name','title'=>'商户名称','type'=>'string'),
					array('name'=>'hb_msg','title'=>'红包祝福语','type'=>'string'),
					array('name'=>'hb_remark','title'=>'红包备注','type'=>'string'),
				)
			),
			array(
							'title'=>'自定义字段',
							'list'=>array(
								array('type'=>'array','name'=>'fileds','add_tip'=>'添加一个字段（温馨提示：这里的自定义表单，在参赛作品详情可看！）',
								'list'=>array(
									array('type'=>'string','name'=>'title','title'=>'字段名称'),	
									array('type'=>'radio','name'=>'type','title'=>'字段类型','options'=>'fieldtypes'),	
									array('type'=>'string','name'=>'paixu','title'=>'排序'),
									array('type'=>'switch','name'=>'is_must','title'=>'是否必填？'),
									array('type'=>'string','name'=>'value','title'=>'选项信息'),	
								),
								'details'=>array(
									array('type'=>'string','name'=>'title','title'=>'字段名称'),	
									array('type'=>'radio','name'=>'type','title'=>'字段类型','options'=>'fieldtypes','option_title'=>'type'),
									array('type'=>'string','name'=>'paixu','title'=>'排序','help'=>'从小到大顺序排序'),
									array('type'=>'switch','name'=>'is_must','title'=>'是否必填？'),
									array('type'=>'string','name'=>'value','title'=>'选项信息','show'=>array('type'=>array(4,5)),'help'=>'单选和多选设置此条信息，选项之间以英文分号;隔开，例如:选项1;选项2;选项3'),
								)
								),
							)
			),
			array(
				'title'=>'幻灯片',
					'list'=>array(
						array(
							'type'=>'array',
							'name'=>'hdps',
							'add_tip'=>'添加一个幻灯片',
								'list'=>array(
									array('type'=>'image','name'=>'picurl','title'=>'幻灯片图片'),
									array('type'=>'string','name'=>'url','title'=>'幻灯片链接'),
									
								),
								'details'=>array(
									array('type'=>'image','name'=>'picurl','title'=>'幻灯片图片','help'=>''),
									array('type'=>'link','from'=>'action','name'=>'url','title'=>'幻灯片链接'),
									
								)
						)
					)
			),
			array(
				'title'=>'板块导航',
					'list'=>array(
									array('type'=>'array','name'=>'bankuai','add_tip'=>'添加一个板块导航',
									'list'=>array(
										array('type'=>'string','name'=>'title','title'=>'导航名称'),
										array('type'=>'image','name'=>'img','title'=>'导航图片'),
										array('type'=>'string','name'=>'action','title'=>'导航链接'),							
									),
									'details'=>array(
										array('type'=>'string','name'=>'title','title'=>'导航名称'),
										array('type'=>'image','name'=>'img','title'=>'导航图片'),							
										array('type'=>'link','from'=>'action','name'=>'action','title'=>'导航链接'),
									)
								),
					)
			),
			array(
				'title'=>'底部导航',
					'list'=>array(
									array('type'=>'array','name'=>'footernav','add_tip'=>'添加一个底部导航',
									'list'=>array(
										array('type'=>'string','name'=>'title','title'=>'导航名称'),
										array('type'=>'icon','name'=>'icon','from'=>'jinyunicon','title'=>'导航图标'),
										array('type'=>'string','name'=>'action','title'=>'导航链接'),							
									),
									'details'=>array(
										array('type'=>'string','name'=>'title','title'=>'导航名称'),
										array('type'=>'icon','name'=>'icon','from'=>'jinyunicon','title'=>'导航图标','help'=>'图标，例如：icon-shouye'),							
										array('type'=>'link','name'=>'action','from'=>'action','title'=>'导航链接'),
									)
								),
					)
			),
		)
	);
	$return['groupid']=pdo_getall('jy_vote_groups',array('uniacid'=>$_SESSION['uniacid'],'isshow'=>1),array('id','title'),'id');
	$return['isfollow']=array('0'=>'不需要关注','1'=>'投票需关注','2'=>'参赛需关注','3'=>'都需要');
	$return['shunxu']=array('0'=>'最新顺序','1'=>'最新倒叙','2'=>'票数倒叙','3'=>'票数顺序','4'=>'礼物倒叙','5'=>'礼物顺序');
	$return['is_shenhe']=array('0'=>'自动审核','1'=>'人工审核');
	$return['type']=array('0'=>'礼物模式','1'=>'非礼物');
	$return['showtype']=array('0'=>'图片模式','1'=>'视频模式');
	$return['code_type']=$this->code_type;
	$return['fieldtypes']=get_form_types();
	$return['gift_type']=$this->gift_type;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$fileds=$postdata['fileds'];
	$data=array(
		'title'=>trim($postdata['title']),
		'thumb'=>trim($postdata['thumb']),
		'noimg'=>trim($postdata['noimg']),
		'starttime'=>intval(strtotime($postdata['starttime'])),
		'endtime'=>intval(strtotime($postdata['endtime'])),
		'paixu'=>intval($postdata['paixu']),
		'groupid'=>intval($postdata['groupid']),
		'isrecommend'=>intval($postdata['isrecommend']),
		'type'=>intval($postdata['type']),
		'infomsg'=>trim($postdata['infomsg']),
		'status'=>intval($postdata['status']),
		'nojiangpin'=>intval($postdata['nojiangpin']),
		//'jiangpin'=>ijson_encode($postdata['jiangpin']),
		'rules'=>trim($postdata['rules']),
		'jiangpin_desc'=>trim($postdata['jiangpin_desc']),
		'gonggao'=>trim($postdata['gonggao']),
		'hb_title'=>trim($postdata['hb_title']),
		'shanghu_name'=>trim($postdata['shanghu_name']),
		'hb_msg'=>trim($postdata['hb_msg']),
		'hb_remark'=>trim($postdata['hb_remark']),
		'isfollow'=>intval($postdata['isfollow']),
		'is_shenhe'=>intval($postdata['is_shenhe']),
		'minpeople'=>intval($postdata['minpeople']),
		'everyoneuser'=>intval($postdata['everyoneuser']),
		'dairyvote'=>intval($postdata['dairyvote']),
		'everyonevote'=>intval($postdata['everyonevote']),
		'songli_max'=>intval($postdata['songli_max']),
		'shouli_max'=>intval($postdata['shouli_max']),
		'is_niming'=>intval($postdata['is_niming']),
		'is_yanzheng'=>intval($postdata['is_yanzheng']),
		'shunxu'=>intval($postdata['shunxu']),
		'is_liping'=>intval($postdata['is_liping']),
		'votezs'=>intval($postdata['votezs']),
		'fabuzs'=>intval($postdata['fabuzs']),
		'songlizs'=>intval($postdata['songlizs']),
		'songlijl'=>intval($postdata['songlijl']),
		'hb_no'=>intval($postdata['hb_no']),
		'hb_draw'=>intval($postdata['hb_draw']),
		'tanchu_rate'=>intval($postdata['tanchu_rate']),
		'hb_rate'=>intval($postdata['hb_rate']),
		'hb_sum'=>intval($postdata['hb_sum']),
		'dairyhb'=>intval($postdata['dairyhb']),
		'dairyuserhb'=>intval($postdata['dairyuserhb']),
		'minhb'=>intval($postdata['minhb']),
		'maxhb'=>intval($postdata['maxhb']),
		'minhb'=>intval($postdata['minhb']),
		'fileds'=>ijson_encode($postdata['fileds']),
		'maxfabu'=>intval($postdata['maxfabu']),
		'nofabu'=>intval($postdata['nofabu']),
		'showtype'=>intval($postdata['showtype']),
		'max_type'=>intval($postdata['max_type']),
		'max_couponid'=>intval($postdata['max_couponid']),
		'max_credit_fee'=>intval($postdata['max_credit_fee']),
		'vote_type'=>intval($postdata['vote_type']),
		'vote_couponid'=>intval($postdata['vote_couponid']),
		'vote_codetype'=>intval($postdata['vote_codetype']),
		'price'=>trim($postdata['price']),
		'is_votemore'=>intval($postdata['is_votemore']),
		'max_votemore'=>intval($postdata['max_votemore']),
		'is_linetime'=>intval($postdata['is_linetime']),
		'onlinetime'=>ijson_encode($postdata['onlinetime']),
		'timenei'=>intval($postdata['timenei']),
		'timenei_num'=>intval($postdata['timenei_num']),
		'hdps'=>ijson_encode($postdata['hdps']),
		'bankuai'=>ijson_encode($postdata['bankuai']),
		'footernav'=>ijson_encode($postdata['footernav']),
	);
	$rid=intval($postdata['id']);
	if($rid){
		pdo_update('jy_vote_reply',$data,array('id'=>$rid,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_vote_reply',$data);
		$rid=pdo_insertid();
	}
	exi('操作成功！','','list');
}
if($_RQ['op']=='max_get'){
	$id=intval($_RQ['id']);
	$this->model('model')->max_get($id);
	exi('发放成功！','','list');
}
if($_RQ['op']=='jplist'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'rid'=>intval($_RQ['id']));
	$this->session('rid',intval($_RQ['id']));
	$rid=$this->session('rid');
	$list=pdo_getall('jy_vote_liping',$params,$fields,'','id desc');
	$return['list']=$list;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回活动列表'),
			array('op'=>'jplist','query'=>'id='.$rid,'title'=>'礼品列表'),
			array('op'=>'editjp','title'=>'添加礼品'),	
		),
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_op'=>'deljp','list'=>array(
			array('name'=>'title','title'=>'礼品名称','type'=>'string'),
			array('name'=>'price','title'=>'价格','type'=>'string'),
			array('name'=>'picurl','title'=>'活动封面','type'=>'image'),
			array('name'=>'jifen','title'=>'积分数/赞数','type'=>'string'),
		),'action' => 
		    array (
			       array('type'=>'href','op'=>'editjp','title'=>'编辑'),
		),)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='editjp'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_vote_liping',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$item=array();
	}
	$rid=$this->session('rid');
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'postjp',
		'tabs'=>array(
			array('op'=>'jplist','query'=>'id='.$rid,'title'=>'礼品列表'),
			array('op'=>'editjp','title'=>'添加礼品'),	
		),
		'edit'=>array(
					array('name'=>'title','title'=>'礼品名称','type'=>'string'),
					array('name'=>'picurl','title'=>'礼品封面','type'=>'image'),
					array('name'=>'price','title'=>'礼品价格','type'=>'string'),
					array('name'=>'jifen','title'=>'礼品积分/赞数','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='postjp'){
	$postdata=get_postdata();
	$data=array(
		'title'=>trim($postdata['title']),
		'picurl'=>trim($postdata['picurl']),
		'price'=>$postdata['price'],
		'jifen'=>intval($postdata['jifen']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_vote_liping',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['rid']=$this->session('rid');
		pdo_insert('jy_vote_liping',$data);
		$id=pdo_insertid();
	}
	exi('操作成功！','','goback');
}
if($_RQ['op']=='deljp'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请选择礼品！','','list');
	}
	pdo_delete('jy_vote_liping',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	exi('删除成功！');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_vote_reply',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的活动！','error');
	}
	$post=get_postdata();
	if(isset($post['status'])){
		pdo_update('jy_vote_reply',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	if(isset($post['isrecommend'])){
		pdo_update('jy_vote_reply',array('isrecommend'=>intval($post['isrecommend'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}
if($_RQ['op']=='votelog'){
	$id=intval($_RQ['id']);
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(isset($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=intval($_RQ['mid']);
	}
	if(isset($_RQ['id'])){
		$oids=pdo_getall('jy_vote_opus',array('rid'=>$id),'id','id');
		if($oids){
			$oids=array_keys($oids);
		}else{
			$oids=-1;
		}
		$params['oid']=$oids;
		$return['params']['id']=$id;
	}
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['psize']){
		$_SESSION['psize']=$_RQ['psize'];
	}
	$psize = $_SESSION['psize']?:10;
	$list=pdo_getslice('jy_vote_votelog',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as $k=>&$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['title']=pdo_getcolumn('jy_vote_opus',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['oid']),'title');
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'export'=>'export',
		'list'=>array('data'=>'list','total'=>$total,'psize'=>$psize,'edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'会员信息_Member','type'=>'member'),
			array('name'=>'title','title'=>'作品名称','type'=>'string'),
			array('name'=>'user_ip','title'=>'IP','type'=>'string'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		)),
		'search'=>array(
			array('type'=>'choose','width'=>15,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
		),
	);
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='export'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(isset($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=intval($_RQ['mid']);
	}
	if(isset($_RQ['id'])){
		$oids=pdo_getall('jy_vote_opus',array('rid'=>$_RQ['id']),'id','id');
		if($oids){
			$oids=array_keys($oids);
		}else{
			$oids=-1;
		}
		$params['oid']=$oids;
		$return['params']['id']=$_RQ['id'];
	}
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['psize']){
		$_SESSION['psize']=$_RQ['psize'];
	}
	$psize = $_SESSION['psize']?:10;
	$list=pdo_getall('jy_vote_votelog',$params,'','','id desc');
	if($list){
		foreach($list as $k=>&$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['nickname']=$item['member']['nickname'];
			$item['createtime']=date('Y-m-d',$item['createtime']);
			$item['title']=pdo_getcolumn('jy_vote_opus',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['oid']),'title');
		}
	}
	$header=array(
		'nickname'=>'昵称',
		'title'=>'作品标题',
		'user_ip'=>'IP',
		'createtime'=>'投票时间',
	);
	cfc('tools')->export2excel($header,$list,'投票记录');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_vote_reply',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}